package cn.edu.hqu.cst.android.recyclerviewtest.adapters;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.view.menu.MenuView;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.hqu.cst.android.recyclerviewtest.R;
import cn.edu.hqu.cst.android.recyclerviewtest.beans.ItemBean;

public class ListViewAdapter extends RecyclerView.Adapter<ListViewAdapter.InnerHolder>{

private final List<ItemBean>  mData;
public ListViewAdapter(List<ItemBean> data){
    this.mData= data;
}

    @NonNull
    @Override
    public InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
   View view= View.inflate(parent.getContext(), R.layout.item_list_view,null);
        return new InnerHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull InnerHolder holder, int position) {
    holder.setData(mData.get(position));

    }

    @Override
    public int getItemCount() {
    if(mData!=null)
        return mData.size();
        return 0;
    }

    public static class InnerHolder extends RecyclerView.ViewHolder {
    private final ImageView  mIcon;
        private final TextView mTitle;

        public InnerHolder(@NonNull View itemView) {
            super(itemView);
            mIcon = (ImageView) itemView.findViewById(R.id.list_view_icon);
            mTitle = (TextView) itemView.findViewById(R.id.list_view_title);
        }

        public void  setData(ItemBean itemBean) {
            mIcon.setImageResource(itemBean.icon);
            mTitle.setText(itemBean.title);
        }

    }

}

